home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
awe2-0_1.lha
/
awe2-0.1
/
Src
/
RCS
/
Semaphore.cc,v
< prev
next >
Wrap
Text File
|
1989-05-04
|
3KB
|
222 lines
head 3.2;
branch ;
access ;
symbols ;
locks grunwald:3.2; strict;
comment @@;
3.2
date 89.02.20.15.37.11; author grunwald; state Exp;
branches ;
next 3.1;
3.1
date 88.12.20.13.49.08; author grunwald; state Exp;
branches ;
next 1.2;
1.2
date 88.10.30.13.03.20; author grunwald; state Exp;
branches ;
next 1.1;
1.1
date 88.09.18.16.42.29; author grunwald; state Exp;
branches ;
next ;
desc
@@
3.2
log
@Start using Gnu library heaps for schedulers
@
text
@// This may look like C code, but it is really -*- C++ -*-
//
// Copyright (C) 1988 University of Illinois, Urbana, Illinois
//
// written by Dirk Grunwald (grunwald@@cs.uiuc.edu)
//
#include "CpuMultiplexor.h"
#include "Semaphore.h"
#include "FifoScheduler.h"
#include "Thread.h"
Semaphore::Semaphore(int count, ThreadContainer *scheduler, bool debug)
: (debug)
{
if (scheduler == 0) {
pScheduler = new FifoScheduler;
} else {
pScheduler = scheduler;
}
pCount = count;
};
Semaphore::~Semaphore()
{
lock.reserve();
if (pScheduler != 0) {
if (! pScheduler -> isEmpty() ) {
cerr << "[Semaphore] Attempted to delete non-empty semaphore\n";
exit(1);
}
delete pScheduler;
pScheduler = 0;
}
lock.release();
}
void Semaphore::reserve()
{
lock.reserve();
if (pCount < 1) {
lock.release();
ThisCpu -> reserveByException( this );
}
else {
pCount--;
lock.release();
}
}
//
// This is only executed in the context of a CpuMultiplexor, never
// a thread.
//
bool
Semaphore::reserveByException(Thread *byWho)
{
bool blocked = 0;
lock.reserve();
if (pCount < 1) {
pScheduler -> add( byWho );
blocked = 1;
}
pCount--;
lock.release();
return( blocked );
}
bool Semaphore::reserveNoBlock()
{
bool gotIt = 1;
lock.reserve();
if (pCount < 1) {
gotIt = 0;
}
else {
pCount--;
}
lock.release();
return( gotIt );
}
void Semaphore::release()
{
Thread *p = 0;
lock.reserve();
if (pCount < 0) {
assert( !pScheduler -> isEmpty() );
p = pScheduler -> remove();
}
pCount++;
lock.release();
if (p != 0) {
ThisCpu -> add(p);
}
}
//
// Need to lock these
//
unsigned Semaphore::size()
{
return(pScheduler -> size());
}
int Semaphore::count(int xcount)
{
lock.reserve();
int tmp = pCount;
pCount = xcount;
lock.release();
return(tmp);
}
int Semaphore::count()
{
lock.reserve();
int tmp = pCount;
lock.release();
return(tmp);
}
void Semaphore::incrCount(int increment)
{
lock.reserve();
pCount += increment;
lock.release();
}
void Semaphore::classPrintOn(ostream& out)
{
int size = pScheduler -> size();
out << " Semaphore with pCount =" << pCount << " and "
<< size << " enqueued tasks\n";
if (size > 0) {
out << "Tasks are:\n" << *pScheduler << "\n";
}
}
@
3.1
log
@Steay version
@
text
@d112 1
d115 1
d121 11
a131 1
return(pCount);
@
1.2
log
@*** empty log message ***
@
text
@@
1.1
log
@Initial revision
@
text
@d1 7
a7 1
#include "HardwareCpu.h"
d53 1
a53 1
// This is only executed in the context of a HardwareCpu, never
d97 1
a97 1
ThisCpu -> add(p,0);
@